package com.cmower.dzone.optional;

import java.util.Optional;

public class CreateOptionalDemo {
    public static void main(String[] args) {
        Optional<String> empty = Optional.empty();
        System.out.println(empty);

        Optional<String> opt = Optional.of("沉默王二");
        System.out.println(opt);

        String name = null;
//        Optional<String> optnull = Optional.of(name); // 抛出 NPE

        Optional<String> optOrNull = Optional.ofNullable(name);
        System.out.println(optOrNull);
    }
}
